package com.company.book_store.web.servlet;

import com.alibaba.fastjson.JSON;
import com.company.book_store.pojo.Bookinfo;
import com.company.book_store.pojo.User;
import com.company.book_store.service.Bookinfoservice;
import com.company.book_store.service.Ibookinfoservice;
import com.company.book_store.service.Iuserservice;
import com.company.book_store.service.UserserviceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet("/detailInfo")
public class detailInfo extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String account = req.getParameter("account");
        Iuserservice iuserservice = new UserserviceImpl();
        Ibookinfoservice ibookinfoservice = new Bookinfoservice();
        User user= iuserservice.selectByaccount(account);
        List<Bookinfo> list = ibookinfoservice.selectByusername(account);

        Map<Object,Object> map = new HashMap<>();
        map.put("user",user);
        map.put("list",list);
        String jsonStr = JSON.toJSONString(map);
        PrintWriter out = resp.getWriter();
        out.write(jsonStr);

    }
}
